class Api::V1::ConcernsController < Api::V1::BaseController

	prepend_before_filter :signed_in_user
	before_action :set_concern, only: [:show, :edit, :update, :destroy]

	def index
		@concerns = Concern.all
	end

	def create
		@concern = Concern.new(concern_params)
		if @concern.save
			render action: "show"
		else
			render :status => 406,
					:json => {
						:status_code => 406,
						:message => "Error creating resource!",
						:content => @concern.errors.full_messages
					}
		end
	end

	def show
	end

	def update
		if @concern.update(concern_params)
			render :status => 200,
					:json => { 
						:status_code => 200,
						:message => "Resource updated succesfully!",
						:content => ""
					 }
		else
			render :status => 406, 
					:json => {
						:status_code => 406,
						:message => "Error updating resource!"
						:content => @concern.errors.full_messages
					 }
		end
	end

	def destroy
		if @concern.destroy
			render :status => 200,
					:json => { 
						:status_code => 200,
						:message => "Resource deleted succesfully!",
						:content => ""
					}
		else
			render :status => 406, 
					:json => {
						:status_code => 406,
						:message => "Error deleting resource!",
						:content => @concern.errors.full_messages
					}
		end
	end

	private

		def set_concern
     		@concern = Concern.find(params[:id])
     		rescue ActiveRecord::RecordNotFound
				error = "The resource that you were looking for could not be found."
				render :status => 404, 
						:json => { 
							:status_code => 404,
							:message => error ,
							:content => ""
						 }
   		end

		def concern_params
			params.require(:concern).permit(:name)
		end
end